package 数组与方法的练习;

import java.util.Arrays;

public class 打印数组索引 {
    public static void main(String[] args) {
        int[] arr = {21, 22, 23, 24, 25, 26};

        int[] arrnew = printArrays(arr);

        for (int i = 0; i < arrnew.length; i++) {
            System.out.println("数组中偶数索引位置的元素为：" + arrnew[i] + ",");
        }


        //for (int i = 0; i < arr2.length; i++) {
        //    arr2[i] = printArrays(arr);
        //}

        //int[] newarr = new int[6];


        //System.out.println(arr[index]);
        //System.out.println(Arrays.toString(arr));
    }

    public static int[] printArrays(int[] arr) {

        int[] arrnew = new int[(arr.length + 1) / 2];

        for (int i = 0, y = 0; i < arr.length; i++) {
            if (i % 2 == 0) {
                arrnew[y] = arr[i];
                y++;
            }
        }
        return arrnew;
    }

}
